package com.hsd.app.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsd.app.model.HsdMdInfo;
import com.hsd.app.model.HsdSynNames;
import com.hsd.app.service.IDataManageService;
import com.hsd.core.page.entity.PageParams;
import com.hsd.core.page.entity.Pagination;


@Controller
@RequestMapping("/datamanage")
public class SynManageAction {
	@Autowired
	private IDataManageService hpdataService;
	
	/**
	 * 数据管理 ：加载名词信息列表
	 * @param pageParams
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/loadSynList.do")
	public String loadSynList(PageParams pageParams,HttpServletRequest request,ModelMap model){
		String synname = request.getParameter("synname"); 
		Pagination page = hpdataService.loadSynList(pageParams,synname);
		
		model.addAttribute("page",page);
		model.addAttribute("synname",synname); 
		return "app/data/data-syn-list";
	}
	/**
	 * 新增一个名词信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/addOneSyn.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String addOneSyn(HsdSynNames synobj,HttpServletRequest request,ModelMap model){
		Map query = new HashMap();
		query.put("rolecode", synobj);
		Object existData = hpdataService.getUniqueObject(HsdMdInfo.class, query);
		if(null != existData){
			return "该角色已存在！";
		}
		//fbobj.setIsuse(1l);
		synobj.setId(this.hpdataService.getSeqNextVal("seq_hsd_account"));
		 
		hpdataService.save(synobj); 
		 
		return "保存成功！";
	}
	/**
	 * 修改一个名词信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/editOneSyn.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String editOneSyn(HsdSynNames synobj,HttpServletRequest request,ModelMap model){ 
		//hpdataService.save(userobj);
		return "修改成功！";
	}
	
	
	/**
	 * 删除名词信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/delOneSyn.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String delOneSyn(HttpServletRequest request,ModelMap model){
		String id = request.getParameter("id"); 
		HsdSynNames synobj = (HsdSynNames)hpdataService.findByID(HsdMdInfo.class, new Long(id));
		//orgObj.setIsuse(0l);
		hpdataService.saveObject(synobj);
		return "删除成功！";
	}
	
}
